
package com.kanjian.music.network;

import java.util.Date;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.kanjian.music.api.ApiRequestManager;
import com.kanjian.music.api.ApiURL;
import com.kanjian.music.api.RequestEntity;
import com.kanjian.music.database.DatabaseManager;
import com.kanjian.music.entity.RequestCache;
import com.kanjian.music.util.CommonUtil;
import com.kanjian.music.volley.VolleyQueue;

/**
 * 没有activity或者fragment处理的Http请求
 * 
 * @author xuyanjun
 */
public class SimpleHttpRequestUtil {

    public static void doLike(long musicId, boolean isLike) {
        final RequestEntity mEntity = ApiURL.fixSid(isLike ? ApiRequestManager
                .getDoLikeRequest(musicId) : ApiRequestManager.getCancelLikeRequest(musicId));
        VolleyQueue.getRequestQueue().add(
                new StringRequest(mEntity.mMethod, mEntity.mUrl, new Listener<String>() {
                    @Override
                    public void onResponse(String arg0) {
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError arg0) {
                    }
                }) {
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        return mEntity.mParams;
                    }

                    protected Response<String> parseNetworkResponse(NetworkResponse response) {
                        return super.parseNetworkResponse(response);
                    }

                });
    }

    public static void doDelRadioMusic(long musicId, int type) {
        final RequestEntity mEntity = ApiURL.fixSid(ApiRequestManager.getDelRadioMusicRequest(
                (int) musicId, type));
        VolleyQueue.getRequestQueue().add(
                new StringRequest(mEntity.mMethod, mEntity.mUrl, new Listener<String>() {
                    @Override
                    public void onResponse(String arg0) {
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError arg0) {
                    }
                }) {
                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        return mEntity.mParams;
                    }

                    protected Response<String> parseNetworkResponse(NetworkResponse response) {
                        return super.parseNetworkResponse(response);
                    }

                });

    }

}
